//
//  AppDelegate.swift
//  SinaWeibo
//
//  Created by 风不会停息 on 2016/11/12.
//  Copyright © 2016年 风不会停息. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        
        regisiterNSNotifaction()
        
        window = UIWindow(frame: UIScreen.main.bounds)
        window?.backgroundColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
    
//        let vc = WBWelcomeViewController()
        //没有登录。显示访客视图。登录之后显示欢迎界面
        window?.rootViewController = WBUserAccountViewModel.WBUserAccountShared.isloginIN ?WBWelcomeViewController() : WeiboTabBarController()
        
        
        window?.makeKeyAndVisible()
        return true
    }

    private func regisiterNSNotifaction(){
     
        NotificationCenter.default.addObserver(self, selector: #selector(switchRootViewController(n:)), name: Notification.Name(kChoseRootViewController), object: nil)
        
    }
    @objc private func switchRootViewController(n:Notification){
        let vc = (n.object == nil ? WeiboTabBarController() : WBWelcomeViewController())
        //设置根视图控制器
        window?.rootViewController = vc

    }


}

